/* 
 * File:   Pair.h
 * Author: marko
 *
 * Created on March 7, 2015, 6:43 PM
 */

#ifndef __PAIR_H__
#define	__PAIR_H__

namespace core {
    namespace util {

        template<typename T> class Pair {
        private:
        protected:
            T first;
            T second;
        public:

            Pair() {
            }

            Pair(T first, T second) {
                this->first = first;
                this->second = second;
            }

            Pair(const Pair& other) {
                first = other.first;
                second = other.second;
            }

            virtual ~Pair() {
            }

            Pair& operator=(Pair other) {
                first = other.first;
                second = other.second;
                return *this;
            }

            T getFirst() {
                return first;
            }

            T getSecond() {
                return second;
            }

            const T& getFirst() const {
                return first;
            }

            const T& getSecond() const {
                return second;
            }

            bool operator==(const Pair &other) const {
                return (first == other.first && second == other.second);
            }

            operator size_t() const {
                size_t hash = 7U;
                hash = 97U * hash + first;
                hash = 97U * hash + second;
                return hash;
            }
        };

    }
}

namespace std {

    template<typename T> struct hash< core::util::Pair<T> > {

        size_t operator()(const core::util::Pair<T> &kv) const {
            size_t retVal = kv;
            return retVal;
        };
        
    };

    template<typename T> struct hash< core::util::Pair<T>* > {

        size_t operator()(const core::util::Pair<T>* kv) const {
            size_t retVal = *kv;
            return retVal;
        };
        
    };

    struct eqKeyVal {

        template<typename T> bool operator()(core::util::Pair<T>* kv1, core::util::Pair<T>* kv2) const {
            return (kv1->getFirst() == kv2->getFirst() && kv1->getSecond() == kv2->getSecond());
        }
        
    };

}


#endif	/* PAIR_H */

